package com.ruoyi.swla2.controller;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.swla2.domain.BalanceFix;
import com.ruoyi.swla2.service.IBalanceFixService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 分区水平衡修正Controller
 *
 * @author gdqt
 * @date 2023-06-21
 */
@RestController
@RequestMapping("/region/regionBalanceFix")
public class BalanceFixController extends BaseController {
    @Autowired
    private IBalanceFixService balanceFixService;

    /**
     * 查询分区水平衡修正列表
     */
    @PreAuthorize("@ss.hasPermi('region:zone:list')")
    @GetMapping("/list")
    public TableDataInfo list(BalanceFix balanceFix) {
        startPage();
        List<BalanceFix> list = balanceFixService.selectBalanceFixList(balanceFix);
        return getDataTable(list);
    }

    @PreAuthorize("@ss.hasPermi('region:zone:list')")
    @GetMapping("/getZoneWaterBalance")
    public AjaxResult getZoneWaterBalance(BalanceFix balanceFix) {
        BalanceFix result = balanceFixService.getZoneWaterBalance(balanceFix);
        return success(result);
    }


    @PreAuthorize("@ss.hasPermi('region:zone:list')")
    @PostMapping("/doCalculateZoneWaterBalanceFix")
    public AjaxResult doCalculateZoneWaterBalanceFix(@RequestBody BalanceFix balanceFix) {
        balanceFixService.doCalculateZoneWaterBalanceFix(balanceFix);
        return success();
    }


    /**
     * 导出分区水平衡修正列表
     */
    @PreAuthorize("@ss.hasPermi('region:zone:export')")
    @Log(title = "分区水平衡修正", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, BalanceFix balanceFix) {
        List<BalanceFix> list = balanceFixService.selectBalanceFixList(balanceFix);
        ExcelUtil<BalanceFix> util = new ExcelUtil<BalanceFix>(BalanceFix.class);
        util.exportExcel(response, list, "分区水平衡修正数据");
    }

    /**
     * 获取分区水平衡修正详细信息
     */
    @PreAuthorize("@ss.hasPermi('region:zone:query')")
    @GetMapping(value = "/{ID}")
    public AjaxResult getInfo(@PathVariable("ID") Long ID) {
        return success(balanceFixService.selectBalanceFixByID(ID));
    }

    /**
     * 新增分区水平衡修正
     */
    @PreAuthorize("@ss.hasPermi('region:zone:add')")
    @Log(title = "分区水平衡修正", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody BalanceFix balanceFix) {
        balanceFix.setTenantId(this.getTenantId());
        return toAjax(balanceFixService.insertBalanceFix(balanceFix));
    }

    /**
     * 修改分区水平衡修正
     */
    @PreAuthorize("@ss.hasPermi('region:zone:edit')")
    @Log(title = "分区水平衡修正", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody BalanceFix balanceFix) {
        return toAjax(balanceFixService.updateBalanceFix(balanceFix));
    }

    /**
     * 删除分区水平衡修正
     */
    @PreAuthorize("@ss.hasPermi('region:zone:remove')")
    @Log(title = "分区水平衡修正", businessType = BusinessType.DELETE)
    @DeleteMapping("/{IDs}")
    public AjaxResult remove(@PathVariable Long[] IDs) {
        return toAjax(balanceFixService.deleteBalanceFixByIDs(IDs));
    }
}
